package day11;

public class TreadDemo {
	public static void main(String[] args) {
		// 默认运行的是主线程
		String name = Thread.currentThread().getName();
		System.out.println(name);// main
		
		MyThread myThread = new MyThread("MyThread");
		// 这不是启动线程，这是一个普通方法调用
		// myThread.run();
		myThread.start();
		String threadName = myThread.getName();
		System.out.println(threadName);
		
		// 实现Runnable接口的方式启动一个线程
		MyRunnable myRunnable = new MyRunnable();
		Thread thread = new Thread(myRunnable, "MyRunnable");
		thread.start();
		
		for (int i = 0; i < 100; i++) {
			System.out.println(name + ":" + i);
		}
	}
	
	public static void main1(String[] args) {
		new Thread(new Runnable() {// 匿名内部类
			
			@Override
			public void run() {
				// TODO Auto-generated method stub
				
			}
		}).start();
	}
}
